/*
 * @Description: 转事件
 */
import { useBaseInfoWithOut } from '@/store/modules/base-info';
import globalData from '@/plugins/data';
import globalMethods from '@/plugins/methods';
import {canTransSecretLevel} from "@/helper/secret-check";
import {fireEvent, getCollEventParams} from "@/handles/common/sdk";

const useBaseInfo = useBaseInfoWithOut();
export async function transform() {
  if (!(await canTransSecretLevel())) {
    return;
  }
  let hook = await fireEvent('relationDoc', getCollEventParams(useBaseInfo.businessData, globalData));
  if (!hook) {
    return;
  }
  const url = `${globalData.ctxPath}/calendar/calEvent.do?method=createCalEvent&subject=${encodeURIComponent(useBaseInfo.baseInfo.businessData.affair.subject)}&beginDate=&endDate=&fromId=${globalData.affairId}&appID=1&beginDate`;
  const dialog = globalMethods.dialog({
    url,
    width: 600,
    height: 600,
    bodyStyle:'padding:0',
    title: this.$i18n('common.new.event.label'),
    checkMax: true,
    transParams: {
      // isDragView:params.isDragView,
      // beginDate:params.beginDate,
      // endDate:params.endDate,
      isView: false
    },
    onCancel() {
      dialog.close();
    },
    onConfirm: () => {
      dialog.getValue({
        dialog, //不穿这个就会提示传参不规范
        type: 'addEventOK',
        okCallback: () => {
          this.$message.success(this.$i18n('calendar.transmit.ok.label'));
          dialog.close();
        }
      });
    }
  });
}

export default function () {
  return new Promise((resolve) => {
    transform.call(this);
    resolve();
  });
}
